package com.banmao.learnandorid;


import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.banmao.learnandorid.databinding.ActivityMainBinding;
import com.banmao.learnandorid.listView.ListViewActivity;
import com.banmao.learnandorid.recycleView.RecycleViewActivity;

public class MainActivity extends AppCompatActivity {

    private Button btn1;
    private Button btn2;
    private Button btn3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn1 = findViewById(R.id.btn_1);
        btn2 = findViewById(R.id.btn_2);
        btn3 = findViewById(R.id.btn_3);

        setClickListener();

    }

    private void setClickListener() {
        OnClick onClick = new OnClick();

        btn1.setOnClickListener(onClick);
        btn2.setOnClickListener(onClick);
        btn3.setOnClickListener(onClick);
    }

    public class OnClick implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            Intent intent = null;
            switch (view.getId()) {
                case R.id.btn_1:
                    intent = new Intent(MainActivity.this, ListViewActivity.class);
                    break;
                case R.id.btn_2:
                    intent = new Intent(MainActivity.this, RecycleViewActivity.class);
                    break;
                default:
                    intent = null;
            }
            if(intent != null) {
                startActivity(intent);
            } else {
                Log.e("路由", "没有对应按钮路由");
                Toast.makeText(MainActivity.this, "没有对应按钮路由", Toast.LENGTH_SHORT).show();
            }

        }
    }

}